<?php
class Controller{
	
	public function __construct() {
	}
	
	public function __call($method,$arg){
	      throw new Exception('method:'.$method.'不存在');
	}

	//实例化模版引擎
	protected function Template(){
	    return new Template();
	}
	
	protected function ajaxReturn($data, $type = 'JSON',$json_option=0) {
	    $data['referer'] = isset($data['url']) ? $data['url'] : "";
	    $data['state']   = !empty($data['status']) ? "success" : "fail";
	
	    if(empty($type)) $type  =   C('DEFAULT_AJAX_RETURN');
	    switch (strtoupper($type)){
	        case 'JSON' :
	            // 返回JSON数据格式到客户端 包含状态信息
	            header('Content-Type:application/json; charset=utf-8');
                //exit(json_encode($data,$json_option));
				exit(json_encode($data));
	        case 'JSONP':
	            // 返回JSON数据格式到客户端 包含状态信息
	            header('Content-Type:application/json; charset=utf-8');
	            $handler  =   isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER');
	            exit($handler.'('.json_encode($data).');');
	        case 'EVAL' :
	            // 返回可执行的js脚本
	            header('Content-Type:text/html; charset=utf-8');
	            exit($data);
	        case 'AJAX_UPLOAD':
	            // 返回JSON数据格式到客户端 包含状态信息
	            header('Content-Type:text/html; charset=utf-8');
	            exit(json_encode($data));
	    }
	
	}

}